package com.loeng.framework.common.exception;

import com.loeng.framework.common.exception.enums.GlobalErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 服务器异常 Exception
 * @author loeng zhuo
 */
@Data
@NoArgsConstructor
@Getter
@EqualsAndHashCode(callSuper = true)
public final class ServiceException extends RuntimeException {

    /**
     * 全局错误码
     *
     * @see GlobalErrorCodeConstants
     */
    private Integer code;
    /**
     * 错误提示
     */
    private String message;

    /**
     * 构造器
     * @param errorCode 错误码
     */
    public ServiceException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    /**
     * 构造器
     * @param code 错误码
     * @param message 错误提示
     */
    public ServiceException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * setter
     * @param code 错误提示
     */
    public ServiceException setCode(Integer code) {
        this.code = code;
        return this;
    }

    /**
     * setter
     * @param message 错误提示
     */
    public ServiceException setMessage(String message) {
        this.message = message;
        return this;
    }

}
